// v 1.0.1

// Town script for town 31: first tunnel / ? ? ? 1

begintownscript;

variables;

int x,i,j,choice,day3;

body;

beginstate INIT_STATE;

if (get_flag(250,0) > 0) {
		day3 = get_flag(250,0);
		set_terrain(8,16,137);

		if (what_day_of_scenario() == day3) {
				set_terrain(8,16,137);
				set_terrain(9,11,137);
				set_terrain(9,12,137);
				set_terrain(9,13,137);
				set_terrain(9,14,137);
				set_terrain(12,11,137);
				set_terrain(12,12,484);
				set_terrain(12,13,137);
				set_terrain(12,14,137);
				set_terrain(15,11,484);
				set_terrain(15,12,484);
				set_terrain(15,13,137);
				set_terrain(15,14,137);
				}
		
		if (what_day_of_scenario() == (day3 + 1)) {
				set_terrain(8,16,137);
				set_terrain(9,11,484);
				set_terrain(9,12,484);
				set_terrain(9,13,137);
				set_terrain(9,14,137);
				set_terrain(12,11,137);
				set_terrain(12,12,484);
				set_terrain(12,13,484);
				set_terrain(12,14,137);
				set_terrain(15,11,484);
				set_terrain(15,12,484);
				set_terrain(15,13,137);
				set_terrain(15,14,484);
				}

						
		if (what_day_of_scenario() >= (day3 + 2)) {
				if (get_flag(33,0) == 1) {
						set_terrain(8,16,137);
						set_terrain(9,11,484);
						set_terrain(9,12,484);
						set_terrain(9,13,484);
						set_terrain(9,14,484);
						}
						
				if (get_flag(34,0) == 1) {
						set_terrain(8,16,137);
						set_terrain(12,11,484);
						set_terrain(12,12,484);
						set_terrain(12,13,484);
						set_terrain(12,14,484);
						}
						
				if (get_flag(35,0) == 1) {
						set_terrain(8,16,137);
						set_terrain(15,11,484);
						set_terrain(15,12,484);
						set_terrain(15,13,484);
						set_terrain(15,14,484);
						}
				}
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

if (get_flag(31,0) == 1)
		end();
	message_dialog("You really thought that that was it and you now could safely walk on. Think again.","In front of you, three series of glowing gates block your progress. It seems Thralni didn't want people to come in this way.");
	set_flag(31,0,1);

break;

beginstate 10;
	move_to_new_town(29,58,7);
break;

beginstate 11;
	move_to_new_town(32,10,16);
break;

beginstate 12;
	change_outdoor_location(4,2,33,17);
	move_to_new_town(36,5,13);
break;

beginstate 13;
if (get_flag(31,1) >= 1)
		end();
	if (has_item(484) == 1) {
			reset_dialog();
			add_dialog_str(0,"It seems as though you have made an explosive potion. This would be the perfect spot to use it. Use it?",0);
			add_dialog_choice(0,"Use the potion");
			add_dialog_choice(1,"Don't use it");
			choice = run_dialog(0);
			
				if (choice == 1) {
						message_dialog("You throw the potion to the gates, hoping for an enormous explosion. You wait. The potion hits the ground. Nothing happens. You wait a bit more.","After five minutes of waiting, you are blinded by a white light and an intense heat fills the cave. The potion explodes, leaving almost nothing of the gates. You also notice a door was opened to your right.");
						take_item(484);
						set_terrain(8,16,137);
						set_terrain(9,11,137);
						set_terrain(9,12,137);
						set_terrain(9,13,137);
						set_terrain(9,14,137);
						set_terrain(12,11,137);
						set_terrain(12,12,484);
						set_terrain(12,13,137);
						set_terrain(12,14,137);
						set_terrain(15,11,484);
						set_terrain(15,12,484);
						set_terrain(15,13,137);
						set_terrain(15,14,137);
						set_flag(31,1,1);
						day3 = what_day_of_scenario();
						set_flag(250,0,day3);
						end();
						}
				
				if (choice == 2)
						end();
				}
		if (get_flag(31,2) == 1)
				end();
			message_dialog("Its a pity you don't have something to blow this place up. Maybe you can find something in the laboratories of Thralni which might help you.","");
			set_flag(31,2,1);
break;

beginstate 14;
if (get_flag(31,3) == 1)
		end();
	message_dialog("You open the door and stumble into this small room. It looks as though even blowing up this place wouldn't help. Of course, to get out you'll have to blow the place up, but getting in again will be a problem.","If you would later want to return here, it'd be best to also make these gates useless.");
	set_flag(31,3,1);
break;	

beginstate 15;
if (get_flag(31,1) == 1) {
		message_dialog("Now that you blew this place up, its time to see if there's something on the other side of this door. It might turn out useful.","");
		set_flag(31,1,2);
		end();
		}

if (get_flag(250,0) == 0) {
		if (get_flag(31,4) == 0) {
				message_dialog("This door looks quite suspicious. A door in the middle of some cave is always a bit suspicious, for that matter.","If you could just get it open somehow... Although the lock tells you it will take quite some effort to get it open.");
				set_flag(31,4,1);
				}
		}
break;

beginstate 16;
if (get_flag(29,17) == 0) {

if (get_flag(5,18) > 0) {
		if (what_day_of_scenario() == day3) {
				if (get_flag(31,5) == 0) {
						message_dialog("You're in luck. Thralni didn't get the time yet to try and repair the gates. You can walk in without any problems.","");
						set_flag(31,5,1);
						end();
						}
				}
		
		if (what_day_of_scenario() == (day3 + 1)) {
				if (get_flag(31,6) == 0) {
						message_dialog("Although Thralni did start with the repairing of the gates, he didn't finish it yet. You are free to pass.","");
						set_flag(31,6,1);
						end();
						}
				}

		if (what_day_of_scenario() >= (day3 + 2)) {
				if (get_flag(31,7) == 0) {
						if (get_flag(33,0) == 1) {
								if (get_flag(34,0) == 1) {
										if (get_flag(35,0) == 1) {
												message_dialog("Thralni finished the repairs on the gates, but sadly the power sources are offline. You can continue without any problem.","");
												set_flag(31,7,1);
												end();
												}
										}
								}
						}
				}
		
		if (get_flag(31,8) == 0) {
						
		if (what_day_of_scenario() >= (day3 + 2)) {
				if (get_flag(33,0) == 0) {
						message_dialog("It seems Thralni started and finished at least one part of the gates. You'll have to find another, more dangerous route. You'll have to go from the outside, charging the gates of the castle.","");
						set_flag(31,8,1);
						end();
						}
						
				if (get_flag(34,0) == 0) {
						message_dialog("It seems Thralni started and finished at least one part of the gates. You'll have to find another, more dangerous route. You'll have to go from the outside, charging the gates of the castle.","");
						set_flag(31,8,1);
						end();
						}
						
				if (get_flag(35,0) == 0) {
						message_dialog("It seems Thralni started and finished at least one part of the gates. You'll have to find another, more dangerous route. You'll have to go from the outside, charging the gates of the castle.","");
						set_flag(31,8,1);
						end();
						}
				}		
		}
}

}
break;